#coding = utf-8
import datetime
import time
import unittest

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By


class grid(unittest.TestCase):
    def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("lang=zh-CN.UTF-8")
        self.driver = webdriver.Remote(command_executor="http://192.168.16.32:5444/wd/hub",
                                       options=chrome_options
                                       )
        self.driver.implicitly_wait(3)
        # 打开登录页面并登录
        self.driver.get("http://192.168.16.51/asmart/login/?state=http%3A%2F%2F192.168.16.51%2Fasmart%2Fasmart%2F%23%2Fmonitor%2Farea")
        self.driver.find_element(By.ID,"username").send_keys("tongyao")
        self.driver.find_element(By.ID,"password").send_keys("Asmart@123456789")
        # self.driver.find_element(By.ID,"validCode").send_keys("1")
        time.sleep(2)
        self.driver.find_element(By.XPATH,"//button/span[text()='登 录']").click()
        time.sleep(5)

    def test_grid(self):

            # 点击主泵1A
            actions = ActionChains(self.driver)
            actions.move_to_element(self.driver.find_element(By.XPATH,"//div[@class='ant-row index_modelName__q034c']")).perform()
            self.driver.find_element(By.XPATH,"//span[text()='主泵1A']").click()
            # 页面数据多  加载时间较长
            time.sleep(20)
            self.driver.find_element(By.ID,"rc-tabs-0-tab-statistics_tabs1").click()


    def tearDown(self):
        # 截图保存
        timestamp_2 = int(datetime.datetime.now().timestamp())
        self.driver.get_screenshot_as_file("./picture/{}.png".format(timestamp_2))
        self.driver.quit()


if __name__ == "__main__":
    unittest.main()